<html>
 <head>
    <title>[var.TITLE]</title>
    <link href="[var.ROOT_CSS_DIR]/main.css" rel="STYLESHEET" type="text/css" charset="iso-8859-1" hreflang="en-us">
    <link href="[var.ROOT_CSS_DIR]/facet/style.css" rel="STYLESHEET" type="text/css" charset="iso-8859-1" hreflang="en-us">
    <script type="text/javascript" src="[var.ROOT_DIR]js/common.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/doiMenuDOM.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/functions.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsmenu.php"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsmenu.cfg"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsformgrid.php?session=[var.SessionVar]"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsmasks.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsverify.php?session=[var.SessionVar]"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsinit.php?session=[var.SessionVar]"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jquery.min.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsformgridnew.js"></script>
 </head>
 <body bgcolor="FFFFFF" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
    <table border="0" cellspacing="0" cellpadding="0" width="100%" align="[var.POSITION]">
        <tr>
            <td>[tbs_include.onshow;file=[var.HTMLHeader];getob;]</td>
        </tr>
        <tr>
            <td>
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td class="mainmenu2"><img src="images/spacer.gif" height="1" width="1"></td>
                </tr>
                <tr>
                    <td background="[var.ROOT_IMG_DIR]/back-menu.gif">
                    <table border="0" cellspacing="0" cellpadding="0" width="100%">
                        <tr>
                            <td>
                            <script language="JavaScript" type="text/JavaScript">menu.Build();</script>
                          </td>
                          <td class="head-login">Login as [var.USERPROFILE_NAME]</td>
                        </tr>
                      </table>
                    </td>
                </tr>
                <tr>
                    <td class="mainmenu2"><img src="images/spacer.gif" height="1" width="1"></td>
                </tr>
            </table>
            </td>
        </tr>
        <tr height="100%">
            <td>
            <table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
                <tr valign="top">
                    <td width="100%">
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr>
                                <td class="head-path"></td>
                                <td class="corner-date">[var.CORNER_DATE]</td>
                            </tr>
                        </table>
                        <table border="0" cellspacing="0" cellpadding="5" width="100%">
                            <tr>
                                <td class="FacetHeaderContent" >.:[var.SubHeaderTitle]:.</td>
                            </tr>
                        </table>

                        <table border="0" cellspacing="0" cellpadding="5" width="100%">
                            <tr>
                                <td class="contentTitleOperational">
                                Menu
                                </td>
                            </tr>
                            <tr>
                                <td class="contentOperational">
                                <table cellspacing="2" cellpadding="0">
                                 <tr>
                                   <td>
                                    <input type="button" name="Action" value="<<Back" class="button" onClick="self.location.replace('[sys.script_name]')">
                                   </td>
                                   <td>[tbs_check;block=td;if [var.USER_CANPRINT]=1]
                                    <input type="button" name="Action" value="Print Surat Jalan" class="button" onClick="OpenPDF('[sys.script_name]?PageMode=PDF&[var.PRIMARY_KEY]=[var.PRIMARY_VALUE]&office=[var.KTRASL]')">
                                   </td>
                                   <td>[tbs_check;block=td;if [var.FormMode]!='Edit']
                                    <input name="FormAction" type="submit" value="Save" class="button" ONCLICK="if(CheckAll()) {this.form.submitted = true; return true;}">
                                   </td>
                                   <td>[tbs_check;block=td;if [var.FormMode]!='Edit']
                                    <input type="button" name="Action" value="Add New" class="button" onClick="self.location.replace('[sys.script_name]?PageMode=Form')">
                                   </td>
                                   <td>
                                    <input type="button" name="Action" value="Done" class="button" onClick="self.location.replace('[var.SERVER_URL]')">
                                   </td>
                                 </tr>
                                </table>
                                </td>
                            </tr>
                            <tr>
                                <td class="contentOperational">
                        <!-- FORM SECTION -->
                        <table border="0" cellspacing="0" cellpadding="0" width="70%">
                        <form method="post" action="[var.FormAction]" name="[var.HTMLFormName]" ONSUBMIT="if (this.submitted) return true; else return false;">
                              <tr>
                                <td class="fieldCaption" align="right">ID No.</td>
                                <td class="fieldCaption" width="2">:</td>
                                <td class="fieldCaption">
                                    <input type="text" name="[headbln.nobkt]" value="[tbs_check;if [var.FormMode]=Edit;then [headblv.nobkt] ;else 'AUTO NUMBERED BY SYSTEM']" maxlength="255" size="25" class="input" onkeyup="this.value=this.value.toUpperCase()" class="input" readonly>
                                    <input type="hidden" name="app1" value="[headblv.app1]">
                                    <input type="hidden" name="nmapp1" value="[headblv.nmapp1]">
                                </td>

                                <td class="fieldCaption" align="right">Job Order Ref</td>
                                <td class="fieldCaption" width="2">:</td>
                                <td class="fieldCaption">
                                <!--select name="[headbln.kdact]" class="input">
                                  <option value="">-</option>
                                  <option value="[actblk.kdact]">[actblk.kdact]-[actblk.actname;block=option]</option>
                                  <option>[headblv.kdact;selected;noerr]</option>
                                </select-->
                                <select name="joList" id="input" [tbs_check;if [var.FormMode]=Edit;then 'disabled';else ''] onchange="GetJo();">
                                        <option value="" selected>Select Value</option>
                                        <option value="1">Job Order</option>
                                    </select>
                                <input type="hidden" id="jo_ido" name="jo_ido" value="[headblv.jo_id;noerr]" class="input" maxlength="50"  size="10" [tbs_check;if [var.FormMode]=Edit;then 'disabled';else '']>
                                <input type="text" id="jo_code" name="jo_code" value="[headblv.jo_code;noerr]" maxlength="255" size="25" class="input" readonly>
                                </td>
                              </tr>
                              <tr>
                                <td class="fieldCaption" align="right">Transaction Date</td>
                                <td class="fieldCaption" width="2">:</td>
                                <td class="fieldCaption">
                                    <table border="0">
                                        <tr>
                                            <td>
                                                <input type="text" name="[headbln.tglbkt]" value="[tbs_check;if [var.FormMode]=Edit;then [headblv.tglbkt;frm='dd/mm/yyyy']; else [sys.now;frm='dd/mm/yyyy']]" maxlength="255" size="10" class="input" >
                                            </td>
                                            <td> [tbs_check;block=td;if [var.FormMode]!='Edit']
                                                <a href="javascript:void(0)" onclick="gfPop.fPopCalendar([var.HTMLFormName].[headbln.tglbkt]);return false;" hidefocus>
                                                <img name="popcal" align="absMiddle" src="[var.ROOT_DIR]js/Calendar/pop/calbtn.gif" width="34" height="22" border="0" alt="">
                                                </a>
                                            </td>
                                        </tr>
                                    </table>

                                    <!--input type="text" name="[headbln.tglbkt]" value="[tbs_check;if [var.FormMode]=Edit;then [headblv.tglbkt;frm='dd/mm/yyyy']; else [sys.now;frm='dd/mm/yyyy']]" maxlength="255" size="10" class="input" -->
                                    <!--a href="javascript:void(0)" onclick="gfPop.fPopCalendar([var.HTMLFormName].[headbln.tglbkt]);return false;" hidefocus>
                                    <img name="popcal" align="absMiddle" src="[var.ROOT_DIR]js/Calendar/pop/calbtn.gif" width="34" height="22" border="0" alt=""></a-->

                                </td>

                                <td class="fieldCaption" align="right">Payment To (Driver)</td>
                                <td class="fieldCaption" width="2">:</td>
                                <td class="fieldCaption">
                                <select name="receivedList" class="input" onchange="GetStaff('advance_payment_to');" [tbs_check;if [var.FormMode]=Edit;then 'disabled';else '']>
                                    <option value="" selected>Select Value</option>
                                    <option value="2">Staff</option>
                                </select>

                                <input type="text" name="[headbln.debnam]" value="[headblv.debnam]" maxlength="255" size="25" class="input" [tbs_check;if [var.FormMode]=Edit;then 'disabled';else ''] onclick="GetReceived(this.value);" >
                                <input type="hidden" name="[headbln.debtur]" value="[headblv.debtur]" id="debtur_code" maxlength="255" size="25">
                                </td>
                              </tr>

                              <tr>
                                <td class="fieldCaption" align="right">Currency</td>
                                <td class="fieldCaption" width="2">:</td>
                                <td class="fieldCaption">
                                <select name="[headbln.curr]" class="input" id="curr_id" onchange="GetRate()">
                                  <option value="">-</option>
                                  <option value="[currformblk.tusymbol]">[currformblk.tusymbol;block=option]</option>
                                  <option>[headblv.curr;selected;noerr]</option>
                                </select>
                                </td>
                              </tr>

                              <tr>
                                <td class="fieldCaption" align="right">Currency</td>
                                <td class="fieldCaption" width="2">:</td>
                                <td class="fieldCaption">
                                    <input type="hidden" name="[headbln.curr]" value="[headblv.curr;selected;noerr]" maxlength="255" size="10" class="input" readonly>
                                    <input type="text" name="[headbln.rate]" value="[headblv.adv_rate;frm='0,000.00';noerr]" maxlength="255" size="10" class="input" readonly>
                                </td>
                              </tr>


                              <tr>
                               <td class="fieldCaption"></td>
                               <td class="fieldCaption"></td>
                               <td align="right" class="fieldCaption"></td>
                              </tr>
                         </table>
                         <!-- FORM SECTION -->
                                </td>
                            </tr>
                        </table>

                        <hr size="1" color="DFDFDF">
                        <div id="spanHeader" style="height: 25px; vertical-align: top; overflow-y: noscroll;">
                        <table border="0" width="100%" cellpadding="3" cellspacing="1" class="FacetFormTABLEOperational" align="left">

                                <tr>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="25">X</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="25">No.</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="200">Services</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="100">Qty Services</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="320">Activities</td>
                                        <!--
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="90"> Qty Activities</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="80">Unit</td>
                                        -->
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="80">Currency</td>
                                        <!--
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="70">Rate</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="90">Amount</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="90">Base Amount</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="90">Tax Rate</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="100">Tax Amount</td>
                                        -->
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="80">Skada</td>
                                        <td nowrap class="FacetColumnTDOperational" align="center" width="130">Total Amount</td>
                                </tr>
                        </table>
                        </div>




                        <div id="spanDetail" class="tariffgrid" style="height: 200px; vertical-align: top; overflow: auto;">

                            <!--Edited by van Smith-->

                            <table border="0" width="100%" cellpadding="3" cellspacing="1" class="FacetFormTABLEOperational" align="left">

                                <tr id="entryAdvance[blgTruckAdvance.#]" style="display:[blgTruckAdvance._display;noerr]">

                                        <td nowrap class="FacetDataTDOperational" align="center" width="25">
                                          <input type="checkbox" name="txtCheckEntryAdvance[blgTruckAdvance.#]" value="[blgTruckAdvance.jobslip_detail_id;noerr]" class="inputRadio">
                                          <input type=hidden name="dk[blgTruckAdvance.#]" value="D">
                                        </td>

                                    <td nowrap class="FacetDataTDOperational" align="center" width="25">
                                      [blgTruckAdvance.#;block=tr].
                                        <input type="hidden" name="jobslip_detail_id[blgTruckAdvance.#]" value="[blgTruckAdvance.jobslip_detail_id;noerr]" class="input">
                                        <input type="hidden" name="jobslip_id[blgTruckAdvance.#]" value="[blgTruckAdvance.jobslip_id;noerr]" class="input">
                                    </td>

                                        <td nowrap class="FacetDataTDOperational" align="center" width="200">

                                           <!--select name="servicesList[blgJobCosting.#]" id="input" onchange="GetServices(this.value,'[blgJobCosting.#]');">
                                             <option value="" selected>Services</option>
                                             <option value="1">Select</option>
                                           </select-->
                                           <input type="hidden" name="services_id[blgTruckAdvance.#]" id="services_id[blgTruckAdvance.#]" value="[blgTruckAdvance.services_id;noerr]" class="input">
                                           <input type="hidden" name="services_code[blgTruckAdvance.#]" value="[blgTruckAdvance.services_code;noerr]" class="input">
                                           <input type="text" name="services_name[blgTruckAdvance.#]" value="[blgTruckAdvance.services_name;noerr]" maxlength="255" size="20"  id="input" readonly>
                                        </td>



                                        <td nowrap class="FacetDataTDOperational" align="center" width="100"><input type="text"  name="qty_service[blgTruckAdvance.#]" value="[blgTruckAdvance.qty_service;noerr]" id="input" size="5" disabled></td>

                                        <td nowrap class="FacetDataTDOperational" align="center" width="320">
                                           <select name="activitiesList[blgTruckAdvance.#]" id="input" [tbs_check;if [var.FormMode]=Edit;then 'disabled';else ''] onchange="GetActivities(this.value,'[blgTruckAdvance.#]');">
                                             <option value="" selected>Activities</option>
                                             <option value="1">Select</option>
                                           </select>
                                           <input type="hidden" name="activities_id[blgTruckAdvance.#]" value="[blgTruckAdvance.activities_id;noerr]" class="input id_activity">
                                           <input type="hidden" name="activities_code[blgTruckAdvance.#]" value="[blgTruckAdvance.activities_code;noerr]" class="input">
                                           <input type="text" name="uraian[blgTruckAdvance.#]" value="[blgTruckAdvance.uraian;noerr]" maxlength="255" size="30" class="gridBox" readonly>
                                        </td>


                                            <input type="hidden"  name="qty_activity[blgTruckAdvance.#]" value="[blgTruckAdvance.qty;noerr]" class="input" id="input" size="5" onkeyup="getBaseAmount('[blgTruckAdvance.#]');">
                                            <input type="hidden"  name="qty_buffer[blgTruckAdvance.#]" class="gridBox" id="input" size="5" >

                                         <input type="hidden"  name="unit[blgTruckAdvance.#]" value="[blgTruckAdvance.unit;noerr;frm='0,000.00']" id="input" size="8" readonly>
                                         <td nowrap class="FacetDataTDOperational" align="center" width="80">
                                            <input type="text"  name="curr[blgTruckAdvance.#]" value="[blgTruckAdvance.curr;noerr;]" id="input" size="8" readonly>
                                         </td>
                                         <input type="hidden"  name="rate_activities[blgTruckAdvance.#]" value="[blgTruckAdvance.rate;noerr;frm='0,000.00']" id="input" size="8" readonly>

                                         <!--input type="hidden"  name="jumlah[blgTruckAdvance.#]" value="[blgTruckAdvance.jumlah;noerr;frm='0,000.00']" id="input" size="11" class="amount" readonly-->
                                         <input type="hidden"  name="jumlah_buffer[blgTruckAdvance.#]" id="input" size="11" class="amount" >

																				 <input type="hidden"  name="base_amount[blgTruckAdvance.#]" value="[blgTruckAdvance.base_amount;noerr;frm='0,000.00']" id="input" size="11" readonly>
																				 <input type="hidden"  name="base_amount_buffer[blgTruckAdvance.#]" id="input" size="11" >
										
																				 <input type="hidden"  name="tax_desc[blgTruckAdvance.#]" value="[blgTruckAdvance.tax_rate;noerr;frm='0,000.00']" id="input" size="11" readonly>
																				 <input type="hidden"  name="tax_rate[blgTruckAdvance.#]" value="[blgTruckAdvance.tax_rate;noerr;frm='0,000.00']" id="input" size="11" readonly>
										
																				 <input type="hidden"  name="tax_amount[blgTruckAdvance.#]" value="[blgTruckAdvance.tax_amount;noerr;frm='0,000.00']" id="input" size="12" readonly>
																				 <input type="hidden"  name="tax_amount_buffer[blgTruckAdvance.#]" id="input" size="12" readonly>

                                        <td nowrap class="FacetDataTDOperational" align="center" width="80">
                                            <input type="text"  name="skada[blgTruckAdvance.#]" value="[blgTruckAdvance.skada;noerr;]" id="input" size="8" readonly>
                                        </td>

                                        <td nowrap class="FacetDataTDOperational" align="center" width="130">
                                            <input type="text"  name="jumlah[blgTruckAdvance.#]" value="[blgTruckAdvance.jumlah;noerr;frm='0,000.00']" id="input" class="total_amount" size="16" onkeyup="this.form.total_trans.value = SumTotal ('jumlah'); getBaseAmount('[blgTruckAdvance.#]'); maskMode(this.name, this.value); ">
                                            <input type="hidden"  name="max_amount[blgTruckAdvance.#]" value="[blgTruckAdvance.max_amount;noerr;frm='0,000.00']" id="input" class="max_amount" size="16" readonly>
                                        </td>
                                    </tr>
                            </table>

                            <!--End Edited by van Smith-->

                        </div>

                        <!--hr size="1" color="DFDFDF">
                        <div id="spanHeader" style="height: 25px; vertical-align: top; overflow: noscroll;">
                        <table border="0" width="100%" cellpadding="3" cellspacing="1" class="FacetFormTABLEOperational" align="left">
                        <input type=hidden name="NewData" value="[var.NewDataStart]">
                            <tr>
                                <td nowrap class="FacetColumnTDOperational" align="center" width="20">X</td>
                                <td nowrap class="FacetColumnTDOperational" align="center" width="20">No.</td>
                                <td nowrap class="FacetColumnTDOperational" align="center" width="200">Description</td>
                                <td nowrap class="FacetColumnTDOperational" align="center" width="50">AMOUNT</td>
                            </tr>
                        </table>
                        </div>
                        <div id="spanDetail" style="height: 200px; vertical-align: top; overflow: auto;">
                        <table border="0" width="100%" cellpadding="3" cellspacing="1" class="FacetFormTABLEOperational" align="left">

                            <tr id="[blg.#]" style="display:[blg._display;noerr]">
                                <td nowrap class="FacetDataTDOperational" align="right" width="55" align="center">
                                    <input type="checkbox" name="txtCheck[blg.#]" value="[blg.adv_id;noerr]" class="inputRadio">
                                    <input type="hidden" name="adv_id[blg.#]" value="[blg.adv_id;noerr]" maxlength="255" size="25">
                                    <input type="hidden" name="urut[blg.#]" value="[blg.#;noerr]" maxlength="255" size="15" class="input">
                                </td>
                                <td nowrap class="FacetDataTDOperational" align="right" width="55" align="center">[blg.#].</td>
                                <td nowrap class="FacetDataTDOperational" width="500" align="center">
                                <input type="text" name="uraian[blg.#]" value="[blg.uraian;noerr;block=tr]" maxlength="255" size="55" class="input" onkeyup="this.value=this.value.toUpperCase()">
                                </td>
                                <td nowrap class="FacetDataTDOperational" align="center" width="130">
                                <input type="text" name="jumlah[blg.#]" value="[blg.jumlah;noerr;frm='0,000.00']" maxlength="255" size="10" onkeyup="this.form.total_trans.value = SumTotal ('jumlah')" class="inputNumber">
                                </td>
                            </tr>
                        </table>
                        </div-->

                        <div id="spanButton" style="height: 35px; vertical-align: top; overflow-y: noscroll;">
                        <table border="0" width="100%" cellpadding="3" cellspacing="1" class="FacetFormTABLEOperational" align="left">
                            <tr>
                                <td align="right" class="FacetDataTDOperational">Total Amount:  <input type="text" name="total_trans" value="" maxlength="255" size="15" class="inputNumber"></td>
                            </tr>
                            <tr>
                                <td align="right" class="FacetColumnTDOperational">
                                <table border="0" cellspacing="2" cellpadding="0">
                                    <tr>
                                        <td><!--[tbs_check;block=td;if [var.USER_CANINSERT]=1]--> [tbs_check;block=td;if [var.FormMode]!='Edit']
                                            <input name="FormAction" type="submit" value="Next Line" class="button" onClick="return (AddFormGridProject(this,'[var.HTMLFormName].qty_activity'))">
                                        </td>
                                        <td><!--[tbs_check;block=td;if [var.USER_CANUPDATE]=1]--> [tbs_check;block=td;if [var.FormMode]!='Edit']
                                            <input name="FormAction" type="button" value="Delete Line" class="button" onClick="DeleteLinesAdvance()">
                                        </td>
                                        <td><!--[tbs_check;block=td;if [var.USER_CANINSERT]=1][tbs_check;block=td;if [var.USER_CANUPDATE]=1]-->[tbs_check;block=td;if [var.FormMode]!='Edit']
                                            <input name="FormAction" type="submit" value="Save" class="button" ONCLICK="if(CheckAll()) {this.form.submitted = true; return true;}">
                                        </td>
                                        <td><!--[tbs_check;block=td;if [var.USER_CANDELETE]=1]-->[tbs_check;block=td;if [var.FormMode]!='Edit']
                                            <input type="button" name="Action" value="Delete" class="button" onClick="if (confirm('Are you sure want to delete ?')) {[var.HTMLFormName].action='[sys.script_name]?FormAction=Delete&[var.PRIMARY_KEY]=[var.PRIMARY_VALUE]&PageMode=Form&form=[var.HTMLFormName]';[var.HTMLFormName].submit();}">
                                        </td>
                                        <td>[tbs_check;block=td;if [headblv.bs_progress;noerr]=='bs']
                                            <input name="FormAction" type="submit" value="Cancel BS" class="button" onClick="this.form.submitted = true; return true;">
                                        </td>
                                        <!--td>
                                            <input name="FormAction" type="submit" value="Cancel" class="button" onClick="self.location.replace('[sys.script_name]')">
                                        </td-->
                                    </tr>
                                </table>
                                </td>
                                </td>
                            </tr>
                            </form>
                        </table>
                        </div>
                    </td>
                </tr>
            </table>
            </td>
        </tr>
        <tr>
            <td>
            <br>
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td class="footer1"><img src="images/spacer.gif" height="1" width="1"></td>
                </tr>
                <!--tr>
                    <td class="footer2">Prototype Test - Web Application</td>
                </tr-->
            </table>
            </td>
        </tr>
    </table>
 </body>
 <iframe width="174" height="189" name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="[var.ROOT_DIR]js/Calendar/pop/ipopeng.htm" scrolling="no" frameborder="0" style="LEFT: -500px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; Z-INDEX: 999"></iframe>
 <script>


  $(function() {
     //alert("okokok");
     GetTotalAmount();
 });

 //All Rama's Function Start
  function GetJo() {
            //newwin = window.open("ais_transaction_jolist.php?FormName=[var.HTMLFormName]&need_another_var="+need_another_var,"toolcalc","height=400,width=640,noscroll,resizable");
            newwin = window.open("ais_transaction_jolist.php?PageMode=FormTruck&FormName=[var.HTMLFormName]&SendToBack=1", "toolcalc","height=400,width=640,noscroll,resizable");
 }

 //All Rama's Function End


 [var.InitFunction]

 document.[var.HTMLFormName].total_trans.value = SumTotal("jumlah");

 function GetReceived2(val) {
     switch (val){
        case "1":
            newwin = window.open("ais_transaction_custlist.php?FormName=[var.HTMLFormName]","toolcalc","height=400,width=640,noscroll,resizable");
            break;
        case "2":
            newwin = window.open("ais_transaction_stafflist.php?FormName=[var.HTMLFormName]","toolcalc","height=400,width=640,noscroll,resizable");
            break;
        case "3":
            newwin = window.open("ais_transaction_vendorlist.php?FormName=[var.HTMLFormName]","toolcalc","height=400,width=640,noscroll,resizable");
            break;
     }
 }

 function GetReceived(val) {
            newwin = window.open("ais_transaction_stafflist.php?FormName=[var.HTMLFormName]","toolcalc","height=400,width=640,noscroll,resizable");
 }

  function GetStaff(need_another_var) {
            newwin = window.open("ais_transaction_stafflist.php?FormName=[var.HTMLFormName]&need_another_var="+need_another_var,"toolcalc","height=400,width=640,noscroll,resizable");
 }

function OpenCalc(formname, desc, total, act, qty, tarif) {
    newwin = window.open("ais_transaction_calc.php?PageMode=Form&desc="+desc+"&total="+total+"&act="+act+"&qty="+qty+"&tarif="+tarif+"&formname="+formname,"toolcalc","height=10,width=450,noscroll,resizable")
}

 function OpenPrincipal (number) {
    newwin = window.open("ais_transaction_receipt_entry.php?PageMode=Page2&FormName=[var.HTMLFormName]&Number="+number,"vessel","height=105,width=300,noscroll,noresizable");
 }

 function OpenPrint (number) {
    newwin = window.open("ais_transaction_adventry.php?PageMode=PrintPreview&nobkt="+number,"print","height=650,width=600,noscroll,noresizable");
 }

 function GetRate() {
     tgl_curr = document.[var.HTMLFormName].tglbkt.value;
     var curr_id = document.getElementById("curr_id").value;
     //if (tgl_curr.length) LoadRPC ("iLoader", "[var.FileName]", "curr="+document.[var.HTMLFormName].curr.value+"&tglbkt="+tgl_curr);
     if (tgl_curr.length) LoadRPC ("iLoader", "[var.FileName]", "curr="+curr_id+"&tglbkt="+tgl_curr);
 }

 function CheckPeriod () {
     var ledger = document.[var.HTMLFormName].tglbkt.value;
     var value = "open";

     var param = 'ledger='+ledger;
     $.ajax({ type: "post", url: "ais_transaction_check_period.php", data: param, dataType: "xml",
         success: function(xml){
            $('status', xml).each(function(i){
               value = $('periodstatus', this).text();
            });
        },
        async:   false,
     });

     if(value == "open"){
        return true;
     }else{
        alert('Invalid Date, Period Already Closed Or Not Yet Opened!');
        return false;
     }
 }

 function GetSkada() {
     skada1 = document.[var.HTMLFormName].thbl.value;
     if (skada1.length) LoadRPC ("iLoader", "[var.FileName]", "thbl="+document.[var.HTMLFormName].thbl.value);
 }

 function SumTotal (component) {
     oMask = new Mask('#,###.#0', 'number');
     var comp_str = "document.[var.HTMLFormName]."+component;

     var TotalComponent = [var.MaxGrid] + [var.NewDataStart] - 1;
     var sum_all = 0;
     var subtotal = 0;
     var js_str = "";

     for (x=1;x<=TotalComponent;x++) {
       js_str = "subtotal = "+comp_str+x+".value";
       eval (js_str);

       if (subtotal.length) subtotal = StrToNumber(subtotal);
       else subtotal = 0;

       sum_all = sum_all + parseFloat(subtotal);
     }
     return oMask.format(sum_all);
 }

  function GetActivities(val,no_urut) {
      //eval("service_id = document.getElementById('services_id" + no_urut +"').value");
      //var service_id = document.getElementById("services_id").value;


        var jo_id = document.getElementById("jo_ido").value;
        var debtur_code = document.getElementById("debtur_code").value;
        var curr_id = document.getElementById("curr_id").value;

        if (CheckRefAct()){
            newwin = window.open("ais_transaction_actnrlist.php?FormName=[var.HTMLFormName]&SendToBack=1&PageMode=TruckAdvanceForm&no_urut="+ no_urut + "&jo_id=" + jo_id + "&staff_code=" + debtur_code + "&curr_id=" + curr_id, "toolcalc","height=400,width=640,noscroll,resizable");
        }
 }

 function AddFormGridProject (cname,firstelemen) {
    var lastname ="";
    //alert("test");
    if (VerifyGridProject(reccount)==false) {
        return false
    }

    $(".gridBox:visible").each(function(n) {

        n = n+1;
        reccount = n;
        lastname = this.name;
        //alert(this.name);
    });

    lastname = lastname.substring(6);

    //alert("bufferku: " + bufferku);
    //alert("rec: " + reccount);
    //reccount = 5;
    //bufferku = parseInt(bufferku)+1;

    lastname = parseInt(lastname)+1;


    //alert("reccount: " + reccount);

    if (reccount>=100) {
        cname.disabled = true;
    }

    var objrow = document.getElementById("entryAdvance" + lastname);
     //eval("var objrow = document.getElementById(jobCosting" + reccount + ")");
    //alert(reccount);
    if (objrow.style.display == 'none') {
        objrow.style.display = '';
    }

    eval(firstelemen+''+lastname+'.focus()');
    //alert(firstelemen+''+reccount);

    return false;
 }

 function VerifyGridProject (x) {
    err_message = '';
    last_focus =0;
    if (err_message.length) {//alert(err_message);
    return false} else return true
 }

 function GetTotalAmount(){

    var total = 0;

    oMask = new Mask('#,###.#0', 'number');

     //alert('bbb');
       $(".total_amount:visible").each(function(n) {

        //alert(this.value);
        var val = this.value;

        if(val == "") {
            val = 0;
        }

        val = String(val);
        val = (val.replace(/,/g, "")) * 1;

        total += val;
        //alert(this.name);
    });

    masktotal = oMask.format(total);
    //alert("total:" + masktotal);
    $("input[name=total_trans]").val(masktotal);

    }

  function DeleteLinesAdvance(){
    $("input[name^=txtCheckEntryAdvance]").each(
      function(){
        if($(this).attr('checked')) {
            //alert($(this).val());
            var num = String($(this).attr('name')).replace('txtCheckEntryAdvance','');
            //alert('num: ' + num);
            $('tr#entryAdvance'+num).remove();
        }
      }
    );
 }

 function CheckRefAct(){
    var jo_code = $("input[name=jo_code]").val();
    //var jo_id = document.[var.HTMLFormName].jo_code.value;

    if(jo_code == ""){
        alert("\"Job Order Ref\" tidak boleh kosong");
        return false;
    } else {
        return true;
    }
 }

 function CheckAll(){
    var jo_code = $("input[name=jo_code]").val();
    var actname = $("input[name=uraian1]").val();
    var msg     = "";

    //var jo_id = document.[var.HTMLFormName].jo_code.value;

    if(jo_code == ""){
        msg = "\"Job Order Ref\" tidak boleh kosong \n";
        //alert("\"Job Order Ref\" tidak boleh kosong");
    }
    if(actname == "") {
        msg = msg + "\"Activities\" tidak boleh kosong \n";
    }

    if (msg == ""){
        return true;
    } else {
        alert(msg);
        return false;
    }
 }

 function getBaseAmount(urut){

    oMask = new Mask('#,###.#0', 'number');

   var max_amount = eval("document.[var.HTMLFormName].max_amount"+urut+".value");
   var qty_buffer = eval("document.[var.HTMLFormName].qty_buffer"+urut+".value");
   var jumlah_buffer = eval("document.[var.HTMLFormName].jumlah_buffer"+urut+".value");
   var tax_amount_buffer = eval("document.[var.HTMLFormName].tax_amount_buffer"+urut+".value");
   var base_amount_buffer = eval("document.[var.HTMLFormName].base_amount_buffer"+urut+".value");
   //alert("base_amount:"+base_amount_buffer);

   var qty_activity = eval("document.[var.HTMLFormName].qty_activity"+urut+".value");
   var rate = eval("document.[var.HTMLFormName].rate_activities"+urut+".value");
   var curr = eval("document.[var.HTMLFormName].curr"+urut+".value");
   var tax_rate = eval("document.[var.HTMLFormName].tax_rate"+urut+".value");
   var jumlah = 0;
   var baseAmount = 0;
   var tax_amount = 0;
   var rupiah = 0;

   var maskcbt_idr = 0;
   var maskcbt_usd = 0;
   var maskcat_idr = 0;

   var rbt_idr = 0;
   var rbt_usd = 0;
   var rat_idr = 0;
   var rat_usd = 0;

   var cbt_idr = 0;
   var cbt_usd = 0;
   var cat_idr = 0;
   var cat_usd = 0;

   var plbt_idr = 0;
   var plat_usd = 0;
   var plat_idr = 0;

   var amountCounter = 0;
   var totalAmountCounter = 0;
   var currCounter = "";

   //Parse the Tax
   var tax_arr = tax_rate.split("-");

   var tax_val = parseFloat(tax_arr[0]);
   var tax_text = tax_arr[1];
   //End Parse the Tax

   /*var counter = 0;
   var n = 0;
   var reccount = 0;
   var amount = 0;
   var baseAmount = 0;
   var tax_amount = 0;
   var total_amount = 0;
*/
   //error handling for rate
   /*if(rate == "") rate = 0;
   else if (!IsNumeric(rate)) alert('Rate should be Numeric value');

   //error handling for Quantity
   if(qty_activity == "") qty_activity = 0;
   else if (!IsNumeric(qty_activity)) alert('Quantity should be Numeric value');

   //error handling for Tax Rate
   if(tax_rate == "") tax_rate = 0;

   //Parse to Integer
   qty_activity = parseInt(qty_activity);*/
   //rate = parseInt(rate);

   if(curr == "IDR")
   {
       rate = String(rate);
       rate = (rate.replace(/,/g, "")) * 1;

      baseAmount = qty_activity * rate;
      jumlah = qty_activity * rate;
   }

   else if(curr == "USD")
   {
      rate = String(rate);
      rate = (rate.replace(/,/g, "")) * 1;

      baseAmount = qty_activity * rate * [var.kursUSD];
      jumlah = qty_activity * rate;
   }

   //Counting the Tax
   ///tax_amount = baseAmount * tax_rate;

   //Counting the Total
   ///total_amount = baseAmount + tax_amount;

    if(tax_text == "exclude")
   {
     if(curr == "IDR")
     {

         baseAmount = String(baseAmount);
         baseAmount = (baseAmount.replace(/,/g, "")) * 1;
         //tax_amount = baseAmount * tax_val;
         rupiah = baseAmount * tax_val;
         tax_amount_usd = 0;

         tax_amount = String(tax_amount);
         tax_amount = (tax_amount.replace(/,/g, "")) * 1;
         //total_amount = baseAmount + tax_amount;
         rupiah = baseAmount + tax_amount;
         total_amount_usd = 0;

     }  else if(curr == "USD")

     {
         baseAmount = String(baseAmount);
         baseAmount = (baseAmount.replace(/,/g, "")) * 1;
         tax_amount = jumlah * tax_val * [var.kursUSDTax];
         tax_amount_usd = jumlah * tax_val.toFixed(2);

         tax_amount = String(tax_amount);
         tax_amount = (tax_amount.replace(/,/g, "")) * 1;
         //total_amount = baseAmount + tax_amount;
         rupiah = baseAmount + tax_amount;
         total_amount_usd = jumlah + tax_amount_usd;
         total_amount_usd.toFixed(2);
     }
   }


   else if(tax_text == "include")
   {
     if(curr == "IDR")
     {

         //amount = String(amount);
         //amount = (amount.replace(/,/g, "")) * 1;

         jumlah = String(jumlah);
         jumlah = (jumlah.replace(/,/g, "")) * 1;

         tax_amount = 0.1/(1.1 - tax_val) * jumlah;
         tax_amount = tax_amount.toFixed(2);
         tax_amount_usd = 0;

         //total_amount = baseAmount;
         rupiah = baseAmount;
         total_amount_usd = 0;

     }   else if(curr == "USD")

     {

         jumlah = String(jumlah);
         jumlah = (jumlah.replace(/,/g, "")) * 1;

         tax_amount = 0.1/(1.1 - tax_val) * jumlah * [var.kursUSDTax];
         tax_amount = tax_amount.toFixed(2);
         tax_amount_usd = 0.1/(1.1 - tax_val) * jumlah;
         tax_amount_usd = tax_amount_usd.toFixed(2);

         rupiah = baseAmount;
         total_amount_usd = amount.toFixed(2);

     }


   }

   else
   {

     if(curr == "IDR")
     {

         baseAmount = String(baseAmount);
         baseAmount = (baseAmount.replace(/,/g, "")) * 1;
         rupiah = baseAmount;
         total_amount_usd = 0;

     }

     else if(curr == "USD")
     {
         baseAmount = String(baseAmount);
         baseAmount = (baseAmount.replace(/,/g, "")) * 1;
         rupiah = baseAmount;
         total_amount_usd = jumlah;
     }

   }


//return oMask.format(sum_all);



    //Change to Mask Format --Start--
    var maskBaseAmount = oMask.format(baseAmount);
    var maskJumlah = oMask.format(jumlah);
    var maskTaxAmount = oMask.format(tax_amount);
    var maskRupiah = oMask.format(rupiah);
    var maskJumlahBuffer = oMask.format(jumlah_buffer);
    //Change to Mask Format --End--

    max_amount = String(max_amount);
    max_amount = (max_amount.replace(/,/g, "")) * 1;
    var maskMaxAmount = oMask.format(max_amount);

    /*jumlah_buffer = String(jumlah_buffer);
    jumlah_buffer = (jumlah_buffer.replace(/,/g, "")) * 1;

    base_amount = String(base_amount);
    base_amount = (base_amount.replace(/,/g, "")) * 1;

    tax_amount = String(tax_amount);
    tax_amount = (tax_amount.replace(/,/g, "")) * 1;*/

    //alert("max_amount, rupiah"+max_amount+"-----"+rupiah);

jumlah = $("input[name=jumlah"+urut+"]").val();
jumlah = String(jumlah);
         jumlah = (jumlah.replace(/,/g, "")) * 1;

    //alert(rupiah + " & " +max_amount);

    if (jumlah > max_amount){
        alert ("Jumlah cost yang anda masukkan, melebihi nilai aktual");
        //$("input[name=qty_activity"+urut+"]").val(qty_buffer);
        //$("input[name=rupiah"+urut+"]").val(maskMaxAmount);
        $("input[name=jumlah"+urut+"]").val(maskMaxAmount);
        //$("input[name=base_amount"+urut+"]").val(base_amount_buffer);
        //$("input[name=tax_amount"+urut+"]").val(tax_amount_buffer);
        //$("input[name=jumlah_buffer"+urut+"]").val(jumlah_buffer);
        GetTotalAmount();
        return false;
    }


   //alert("quantity: " + qty_activity + ", rate: " + rate + ", amount: " + amount);
   /*eval("document.[var.HTMLFormName].base_amount"+urut+".value = "+ baseAmount);
   eval("document.[var.HTMLFormName].amount"+urut+".value = "+amount);
   eval("document.[var.HTMLFormName].tax_amount"+urut+".value = "+tax_amount);
   eval("document.[var.HTMLFormName].total_amount"+urut+".value = "+total_amount);*/



   //$("input[name=base_amount"+urut+"]").val(maskBaseAmount);
   //$("input[name=jumlah"+urut+"]").val(maskJumlah);
   //$("input[name=tax_amount"+urut+"]").val(maskTaxAmount);
   //$("input[name=rupiah"+urut+"]").val(maskRupiah);
   //GetTotalAmount();

}

 function maskMode(names,values){
    //alert(tes);
    oMask2 = new Mask('#,###.##', 'number');
    $("input[name="+names+"]").val(oMask2.format(values));

 }

  function SumTotal (component) {
     oMask = new Mask('#,###.#0', 'number');
     var comp_str = "document.[var.HTMLFormName]."+component;

     var TotalComponent = [var.MaxGrid] + [var.NewDataStart] - 1;
     var sum_all = 0;
     var subtotal = 0;
     var js_str = "";

     for (x=1;x<=TotalComponent;x++) {
       js_str = "subtotal = "+comp_str+x+".value";
       eval (js_str);

       if (subtotal.length) subtotal = StrToNumber(subtotal);
       else subtotal = 0;

       sum_all = sum_all + parseFloat(subtotal);
     }
     return oMask.format(sum_all);
 }

 </script>
</html>
